package com.ruoyi.project.members.order.controller;

import com.ruoyi.common.constant.SqlOrder;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.members.order.domain.Order;
import com.ruoyi.project.members.order.service.OrderService;
import com.ruoyi.project.user.host.domain.Host;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@RequestMapping("/members/order")
public class OrderController extends BaseController {
    private String prefix = "members/order";

    @Autowired
    private OrderService orderService;


    @RequiresPermissions("members:order:view")
    @GetMapping("")
    public String showView() {
        System.out.println("执行了控制器");
        return prefix + "/order";
    }

    /**
     * 显示页面数据
     *
     * @return
     */
    @RequiresPermissions("members:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo demo(Order order, String cname) {
        System.out.println(order.getOrderCustomertype());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        if(order.getOrderCreatetime()!=null){
            String sorderCreatetime = formatter.format(order.getOrderCreatetime());
            order.setSorderCreatetime(sorderCreatetime);
        }
        startPage();

        List<Order> list = orderService.findOrderByList(order, cname);
        return getDataTable(list);
    }

    /*\
    * 导出
    * */
    @RequiresPermissions("members:order:list")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export() {
        List<Order> exList = orderService.export();
        ExcelUtil<Order> util = new ExcelUtil<Order>(Order.class);
        return util.exportExcel(exList, "订单数据");
    }
}
